import requests
from pyquery import  PyQuery as pq
headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'
}
log_url='https://github.com/login'
post_url='https://github.com/session'
logined_url='https://github.com/settings/profile'
session=requests.session()

def token():
    storage=[]
    response=session.get(url=log_url,headers=headers).text
    #print(response)
    doc=pq(response)
    token=doc('.auth-form input').items()
    for i in token:
        The_storage=i.attr('value')
        storage.append(The_storage)
    return storage[1]

def login(name,passwd):
    post_data={
        'commit':'Sign in',
        'utf8':'✓',
        'authenticity_token':token(),
        'login':name,
        'password':passwd
    }


    response=session.post(url=post_url,data=post_data,headers=headers)
    if response.status_code == 200:
        with open('提交账户密码的页面.html','w',encoding='utf8')as p:
            p.write(response.text)


        #dynamics(response.text)



input_name=input('请输入登陆邮箱:')
input_passwd=input('请输入密码:')
login(input_name,input_passwd)